#include "user_main.h"
#include "ti_msp_dl_config.h"
#include "./order_sensor/order_sensor_app.h"
#include "./order_sensor/order_sensor_bsp.h"
#include "./board_g3507/bsp_g3507std.h"


//////////////////////////////////////////////////////////////////////////
// Timer

// tick
volatile uint32_t g_ticks = 0;
volatile uint32_t g_ticks_inc = 0;

void SysTick_Handler(void)
{
    g_ticks++;
    g_ticks_inc++;
}

static void _user_init( void )
{    
    NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);
    NVIC_EnableIRQ(ADC12_1_INST_INT_IRQN);

    DL_ADC12_enableConversions(ADC12_0_INST);
    DL_ADC12_startConversion(ADC12_0_INST);

    DL_ADC12_enableConversions(ADC12_1_INST);
    DL_ADC12_startConversion(ADC12_1_INST);
}

int main(void)
{
    SYSCFG_DL_init();

    order_sensor_init();
    _user_init();

    adc_0_dma_config(gADCSamples, ADC_SAMPLE_SIZE);
    adc_1_dma_config(gADCSamples_0, ADC_SAMPLE_SIZE);

    while (1) {
        if ( g_ticks  >= 10 ) {    // 1 ms per circle
            g_ticks =0;
        
            DL_ADC12_enableConversions(ADC12_0_INST);
            DL_ADC12_startConversion(ADC12_0_INST);

            DL_ADC12_enableConversions(ADC12_1_INST);
            DL_ADC12_startConversion(ADC12_1_INST);
            order_sensor_act( g_g3507_board_order_array, g_g3507_board_sensor_array, G3507_BOARD_SENSOR_ARRAY_LEN); 

            g3507_board_set_order(  g_g3507_board_order_array  , 15 );
            g3507_board_get_sensor( g_g3507_board_sensor_array , 10 );

        }
    }
}




